package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.pojo.PageA;
import com.bjsxt.pojo.TreeA;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService  menuService;

    //查询同步树形菜单
    @RequestMapping("/findAllMenu3")
    public   List<TreeA>  findAllMenu3(){
        return  menuService.findAll3();
    }

    //删除菜单实现
    @RequestMapping("/removeMenu")
    public   Integer   removeMenu(Integer mid){

        return   menuService.remove(mid);
    }

    //修改菜单的实现
    @RequestMapping("/changeMenu")
    public   Integer   changeMenu(Menu menu){

        return   menuService.change(menu);

    }

    //添加菜单实现
    @RequestMapping("/saveMenu")
    public   Integer   saveMenu(Menu menu){

        return   menuService.save(menu);
    }


    //查询所有菜单实现
    @RequestMapping("/findAllMenu2")
    public List<TreeA> findAllMenu2(@RequestParam(defaultValue = "0") Integer id){

        return   menuService.findAll2(id);
    }

    //查询所有菜单实现
    @RequestMapping("/findAllMenu")
    public PageA<Menu>  findAllMenu(Integer page,Integer rows){

        return   menuService.findAll(page, rows);
    }

    @RequestMapping("/findMoreMenu")
    public List<TreeA>  findMoreMenu(@RequestParam(defaultValue = "0") Integer id, HttpSession  session){

       Admin admin = (Admin) session.getAttribute("admin");

       return  menuService.findMore(admin.getAid(),id);

    }

}
